package com.yer.note.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yer.note.R;
import com.yer.note.entity.LabelDiary;

import java.util.ArrayList;

public class LabelDiaryAdapter extends RecyclerView.Adapter<LabelDiaryAdapter.myViewHodler> {
    private Context context;
    private ArrayList<LabelDiary> labelDiaries;
    private OnItemClickListener mOnItemClickListener;

    public LabelDiaryAdapter() {
    }
    public LabelDiaryAdapter(Context context, ArrayList<LabelDiary> labelDiaries) {
        this.context = context;
        this.labelDiaries = labelDiaries;
    }

    @NonNull
    @Override
    public myViewHodler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view  = LayoutInflater.from(parent.getContext()).inflate(R.layout.nav_label_item,parent,false);
        return new myViewHodler(view);
    }

    @Override
    public void onBindViewHolder(@NonNull myViewHodler holder, int position) {
        LabelDiary labelDiary = labelDiaries.get(position);
        holder.numberView.setText(Integer.toString(labelDiary.getNumber()));
        holder.labelView.setText(labelDiary.getLabel());
        holder.amountView.setText(Integer.toString(labelDiary.getAmount()));
        holder.label = labelDiary.getLabel();
    }

    @Override
    public int getItemCount() {
        return labelDiaries.size();
    }
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    public interface OnItemClickListener{
        void onItemClick(String label);
    }

    public class myViewHodler extends RecyclerView.ViewHolder{
        private TextView numberView;
        private TextView labelView;
        private TextView amountView;
        private String label;
        public myViewHodler(View itemview) {
            super(itemview);
            numberView = itemview.findViewById(R.id.nav_label_number);
            labelView = itemview.findViewById(R.id.nav_label_label);
            amountView = itemview.findViewById(R.id.nav_label_amount);
            itemview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickListener.onItemClick(label);
                }
            });
        }
    }
}
